#include "timerhandleseq.h"
#include "src/Utils/dbconnhelper.h"
#include <QString>
#include<QSqlQuery>
#include<QSqlDatabase>
#include <QSqlRecord>

TimerHandleSeq::TimerHandleSeq(QObject *parent)
    : QObject{parent}
{
    db = dbhelper.openDataBase("conn_SteelNo","SteelRecord");
}

TimerHandleSeq::~TimerHandleSeq()
{
    dbhelper.closeDataBase("conn_SteelNo");
}

void TimerHandleSeq::onTimeOuthandle()
{

    QString Sqlstr = R"(
        use SteelRecord
        select top 1 [SequeceNo]
        from [dbo].[steel]
        Order By SequeceNo DESC
    )";
    QSqlQuery query(db);
    query.exec(Sqlstr);
    while(query.next()){
        int tempSeq = query.record().value("SequeceNo").toInt();
        if(tempSeq != LastSeq){
            LastSeq = tempSeq;
            emit OnSequenecChanged((tempSeq -1));
        }
    }

}
